<?php
namespace app\common\audit\model;

use app\common\config\logic\CommonPickerLogic;
use app\common\config\logic\DictionaryLogic;
use app\common\config\model\ConfigCompany;
use think\Model;
use think\model\concern\SoftDelete;

class AuditConfig extends Model
{
    use SoftDelete;
    protected $defaultSoftDelete = 0;

    protected $type = [
        'condition' => 'json'
    ];

    public function getCompanyAttr($value, $data) {
        $logic = new DictionaryLogic();

        return $logic->getItem($data['company_id'], ConfigCompany::class, ['id', 'title', 'short_name']);
    }

    public function getTagAttr($value, $data) {
        $logic = new CommonPickerLogic();
        return $logic->getPickerItem('timing', $data['timing']);
    }

    // 获取条件的对象
    public function getConditionAttr($value, $data)
    {
        return empty($value) ? [] : json_decode($value, true);
    }
}